import java.util.Comparator;
import java.util.PriorityQueue;

public class PQ {

	static class PQsort implements Comparator<Employeee> {

		@Override
		public int compare(Employeee o1, Employeee o2) {
			return o2.salary - o1.salary;
		}
	}

	public static void main(String[] args) {
		/*
		 * PriorityQueue<Employeee> pq1 = new PriorityQueue<Employeee>();
		 * Employeee emp1 = new Employeee("ramesh", 25000); Employeee emp2 = new
		 * Employeee("om", 27000); Employeee emp3 = new Employeee("kirit",
		 * 22000); Employeee emp4 = new Employeee("anuj", 50000);
		 * pq1.offer(emp1);//use offer() method to add elements to the
		 * PriorityQueue pq1 pq1.offer(emp2); pq1.offer(emp3); pq1.offer(emp4);
		 * System.out.println("List of Emp before comparator..");
		 * while(!pq1.isEmpty()){ System.out.println(pq1.poll()); }
		 */
		PQsort pqs = new PQsort();// get a Comparator
		PriorityQueue<Employeee> pq2 = new PriorityQueue<Employeee>(10, pqs);
		Employeee emp1 = new Employeee("ramesh", 25000);
		Employeee emp2 = new Employeee("om", 27000);
		Employeee emp3 = new Employeee("kirit", 22000);
		Employeee emp4 = new Employeee("anuj", 50000);
		Employeee emp5 = new Employeee("anuj", 60000);
		Employeee emp6 = new Employeee("anuj", 10000);
		Employeee emp7 = new Employeee("anuj", 90000);
		Employeee emp8 = new Employeee("anuj", 30000);
		pq2.offer(emp1);// use offer() method to add elements to the
						// PriorityQueue pq1
		pq2.offer(emp2);
		pq2.offer(emp3);
		pq2.offer(emp4);
		pq2.offer(emp5);
		pq2.offer(emp6);
		pq2.offer(emp7);
		pq2.offer(emp8);
		System.out.println("List of Emp After comparator..");
		while (!pq2.isEmpty()) {
			System.out.println(pq2.poll());
		}
		System.out.println("  the end!");
	}
}

class Employeee {
	String name;
	int salary;

	/**
	 * @param name
	 * @param salary
	 */
	public Employeee(String name, int salary) {
		super();
		this.name = name;
		this.salary = salary;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Employee [" + (name != null ? "name=" + name + ", " : "")
				+ "salary=" + salary + "]";
	}

}
/*
 * import com.Patient; import java.util.Comparator; import
 * java.util.PriorityQueue; public class PQueueTest { public static void
 * main(String[] args) { PriorityQueue<Patient> patientQueue = new
 * PriorityQueue<Patient>(10, new Comparator<patient>() { public int
 * compare(Patient patient1, Patient patient2) { return
 * (patient1.isEmergencyCase() == patient2.isEmergencyCase()) ?
 * (Integer.valueOf(patient1.getId()).compareTo(patient2.getId())) :
 * (patient1.isEmergencyCase() ? -1 : 1); } });
 * 
 * patientQueue.add(new Patient(1, "Patient1", false)); patientQueue.add(new
 * Patient(2, "Patient2", false)); patientQueue.add(new Patient(3, "Patient3",
 * true)); patientQueue.add(new Patient(4, "Patient4", false));
 * patientQueue.add(new Patient(5, "Patient5", true));
 * 
 * System.out.println(); System.out.print("Doctor's waiting for patients  : ");
 * while(true) { Patient currentPatient = patientQueue.poll(); if(currentPatient
 * == null) { break; }
 * 
 * System.out.print(currentPatient.getName() + " <-- "); } System.out.println();
 * } }
 */